package leetcode;

import java.util.Stack;

/**
 * @author Hang
 * @date 2022/10/19
 * @project AutumnOffer
 * @description 946
 **/
public class validateStackSequences {
    public static void main(String[] args) {
        int[] pushed = new int[]{1,2,3,4,5};
        int[] poped = new int[]{4,3,5,1,2};
        System.out.println(validateStackSequences(pushed, poped));
    }
    public static boolean validateStackSequences(int[] pushed, int[] popped) {
        Stack<Integer> st = new Stack<>();
        int cur=0;
        for(int i=0;i<pushed.length;i++){
            st.push(pushed[i]);
            while(!st.empty()&&st.peek()==popped[cur]){
                st.pop();
                cur++;
            }
        }
        return st.empty();
    }
}
